<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        #box{
            width: 200px;
            height: 400px;
        }
        button{
            margin-top: 100px;
            width: 166.4px;
            height: 30px;
            border: none;
            background-color: rgb(240, 110, 110);
        }
        .but{
            opacity: .5;
        }
    </style>
</head>
<body>
    <div id="box">
        <input  v-model="val" type="text"><span @click="add" v-show="flag">X</span>
        <button :disabled="dis" @click="ane"  :class={but:dis}>提交</button>
    </div>
    <script>
        Vue.config.productionTip = false
        new Vue({
            el:"#box",
            data:{
                flag:false,
                val:'',
                //是否禁用
                dis:true,
            },
            watch:{
                val(v){
                    //如果打长度大于0的时候让它显示
                    if(v.length>0){
                        this.flag=true
                        //如果length等于11
                        if(v.length ===11){
                            this.dis=false
                        }else{
                            this.dis=true
                        }
                    }else{
                        this.flag=false
                    }
                },
               
            },
            methods: {
                add(){
                    this.val='';
                    this.dis=true
                },
                ane(){
                    console.log(123);
                }
            },
        })
    </script>
</body>
</html>